package com.vanthan.xoso.jsoup;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.util.Log;

import com.vanthan.xoso.Variables;

public class JsoupLocal {

	public JsoupLocal() {
		super();
	}
	
	
	public StringBuffer parserKetQua(String link){
		Log.e("Link", link);
		StringBuffer strBuffer = new StringBuffer();
//		List<String> strString = new ArrayList<String>();
		try {
			Connection connect = Jsoup.connect(link).timeout(Variables.OUT).ignoreHttpErrors(true);
			Variables.document = connect.get();
			
//			Elements elements = Variables.document.select("div [class = XS bogoc1 kc_XS shadow]");
//			Log.e("TITLE", elements.select("h2").text());
//			Log.e("XXX", elements.size()+"");
			
			Elements elements2 = Variables.document.select("tr.XSMB_ngang");
			Log.e("TITLE1", elements2.select("h2").text());
			Log.e("XXX1", elements2.size()+"");
			for(Element elm : elements2){
				Log.e("Tên giải:", elm.select("td.XSMB_1").text());
				Log.e("kết quả:", elm.select("td.XSMB_2").text());// = kq01
				Log.e("kết quả:", elm.select("td.XSMB_4").text());//= kq02
				
				
				/**
				 * kq01!=null -> 
				 */
			}
			String str = ""; 
			String []array = str.split(" ");
			//function(String string){
			//ktra string != null;
			//return array;
			//}
			
			Elements elements1 = Variables.document.select("h2");
			Log.e("XXX", elements1.size()+"");
			for(Element elm :elements1){
				Log.e("XXX", elm.html());
				parserContent(elm);
//				Log.e("A", parserContent(elm)+"");
				strBuffer.append(parserContent(elm));
			}
		} catch (IOException e) {
			e.printStackTrace();
			Variables.isError=true;
			Log.e("Lỗi pares link Detailed", e.toString()+" "+ link);
		}
		return strBuffer;
	}
	
	
	
	public List<String> parserContent(Element elm){
		List<String> objElm = new ArrayList<String>();
		elm.select("td.XSMB_1").text();
		
		
		objElm.add(elm.select("td.XSMB_1").text());
		return objElm;
	}
}
